package com.yunji.base.dao.impl;

import com.yunji.base.bo.StaffSiteRemoveBO;
import com.yunji.base.dao.IStaffSiteDao;
import com.yunji.base.domain.StaffSiteDO;
import com.yunji.base.dto.StaffSiteQueryDTO;
import com.yunji.base.mapper.IStaffSiteMapper;
import com.yunji.common.base.BaseDaoImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author : peter-zhu
 * @date : 2024/12/12 19:53
 * @description : TODO
 **/
@Repository
public class StaffSiteDaoImpl extends BaseDaoImpl<IStaffSiteMapper, StaffSiteDO> implements IStaffSiteDao {
    @Override
    public List<StaffSiteDO> listByStaffId(Long staffId) {
        return lambdaQuery().eq(StaffSiteDO::getStaffId, staffId).list();
    }

    @Override
    public List<StaffSiteDO> listBySiteId(Long siteId) {
        return lambdaQuery().eq(StaffSiteDO::getSiteId, siteId).list();
    }

    @Override
    public List<StaffSiteDO> listByQuery(StaffSiteQueryDTO bo) {
        return lambdaQuery()
                .eq(bo.getSiteId() != null, StaffSiteDO::getSiteId, bo.getSiteId())
                .eq(bo.getStaffId() != null, StaffSiteDO::getStaffId, bo.getStaffId())
                .in(bo.getSiteIds() != null, StaffSiteDO::getSiteId, bo.getSiteIds())
                .list();
    }

    @Override
    public boolean removeByBo(StaffSiteRemoveBO bo) {
        return lambdaUpdate().eq(bo.getSiteId() != null, StaffSiteDO::getSiteId, bo.getSiteId())
                .eq(bo.getStaffId() != null, StaffSiteDO::getStaffId, bo.getStaffId())
                .eq(bo.getId() != null, StaffSiteDO::getId, bo.getId())
                .in(bo.getStaffIds() != null, StaffSiteDO::getStaffId, bo.getStaffIds())
                .remove();
    }

    @Override
    public List<StaffSiteDO> listBySiteIds(List<Long> siteIds) {
        return lambdaQuery().in(StaffSiteDO::getSiteId, siteIds).list();
    }

    @Override
    public boolean removeByStaffIds(List<Long> staffIds) {
        return lambdaUpdate().in(StaffSiteDO::getStaffId, staffIds).remove();
    }
}
